<?php
defined('_JEXEC') or die('Restricted access');
$app = JFactory::getApplication();
$input = $app->input;
$itemid = $input->get('Itemid');

$item  = $input->getArray();
$jsondatas = json_decode( str_replace(' lg ','<',$item['jsonData']) , 1);

$data = $jsondatas['data'];
ksort($data);
foreach ($data as $key => $value) {
    $list[$key]['value'] = $value['value'];
    $list[$key]['name'] = $value['name'];
}

$typename = array_column($jsondatas['data'],'name');
$values = array_column($jsondatas['data'],'count');

$vName = $input->get('view');

$funnels = $this->get('Funnels');
?>
<div class="res-title-rg">
    <span class="fl pos-icon text-c"><i class="audience"></i></span>
    <div class="title-info">
        <h2 class="fontsize20">Conversion</h2>
        <p><a href="#">Home</a>&nbsp;/&nbsp;Audience&nbsp;/&nbsp;Conversion</p>
    </div>
</div>
<div class="ws-content pdall15">
	<div class="camtab">
        <div class="dropdown fr">
	        <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
	            Click to select a funnel
	            <span class="caret"></span>
	        </button>
	        <ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
	        <?php foreach ($funnels as $key => $value): ?>
	            <li class="selected"><a href="/index.php?option=com_console&view=<?php echo $vName; ?>&task=<?php echo $vName; ?>&Itemid=<?php echo $itemid ?>&funnel_id=<?php echo $value->id ?>"><?php echo $value->name?></a></li>
	        <?php endforeach ?>
	        </ul>
        </div>
	</div>
<?php if ($data): ?>
    <div id="main" style="height:520px;"></div>
<?php else: ?>
 	<p class="ws-tips">No report data found.</p>
<?php endif; ?>
</div>
<script type="text/javascript">
	createFunnelChart({
		divId: 'main',
		title: '<?php echo $jsondatas['name'] ?>',
		names: <?php echo json_encode($typename); ?>,
		nodes: <?php echo json_encode($list); ?>
	});
	
</script>
